﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Wechat.Util.ParmsConfig;

namespace WeChat.Web.Filter
{
    public class BaseController : Controller
    {
        /// <summary>
        /// 当前管理员登录状态Cookie
        /// </summary>
        public HttpCookie CurrentCookie
        {
            get
            {
                return LoginInfo.OperaterInfoCookie;
            }
        }

        public BaseController()
        {
            ViewBag.SystemName = ParmsConfigUtil.SystemName;
            ViewBag.PlatId = ParmsConfigUtil.PlatId;
        }

        /// <summary>
        /// 系统错误
        /// </summary>
        /// <returns></returns>
      
        public ActionResult Error()
        {
            return View("Error");
        }

        /// <summary>
        /// 无权限
        /// </summary>
        /// <returns></returns>
       
        public ActionResult NoAccess()
        {
            return View("NoAccess");
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns>
        
        public RedirectResult Login()
        {
            var response = System.Web.HttpContext.Current.Response;
            var request = System.Web.HttpContext.Current.Request;

            if (CurrentCookie != null)
            {
                CurrentCookie.Expires = DateTime.Now.AddDays(-1);
                response.Cookies.Add(CurrentCookie);
            }

            string loginUrl = string.Format("{0}/Account/LogIn?ReturnUrl={1}",
                    ParmsConfigUtil.UserCenterUrl,
                    request.Url.GetLeftPart(UriPartial.Scheme) + request.Url.Host + (request.Url.Port == 80 ? string.Empty : ":" + request.Url.Port));
            return Redirect(loginUrl);
        }
    }
}